#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;

int l[7][7], h[7][7], a[7][7], n;
int inflow[7];

void load()
{
	cin >> n;
	int s, f;
	for (int i = 0; i < n * (n - 1) / 2; i++)
	{
		cin >> s >> f;
		cin >> l[s][f] >> h[s][f] >> a[s][f];
	}
}

int curcost = 0, maxcost;

bool go(int i, int j, int remain)
{
	if (remain < 0) return false;
	if (i == n)
	{
		maxcost = max(maxcost, curcost);
		return true;
	}
	if (j == n + 1)
	{
		if (remain != 0) return false;
		return go(i + 1, i + 2, inflow[i + 1]);
	}
	bool t = false;
	for (int k = l[i][j]; k <= h[i][j]; k++)
	{
		if (remain - k < 0) break;
		curcost += (k ? a[i][j] : 0) + k * k;
		inflow[j] += k;
		t |= go(i, j + 1, remain - k);
		inflow[j] -= k;
		curcost -= (k ? a[i][j] : 0) + k * k;
	}
	return t;
}

void solve()
{
	maxcost = 0;
	for (int i = 0; i <= 30; i++)
	{
		memset(inflow, 0, sizeof inflow);
		inflow[1] = i;
		if (go(1, 2, inflow[1]))
		{
			cout << i << " " << maxcost;
			return;
		}
	}
	cout << "-1 -1";
}

#define file "c"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}
